﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace Open_Task_Request_System.Models
{
    public class TaskModel
    {
        public Guid? Id { get; set; }

        [Required(ErrorMessage = "Please enter a Task Name")]
        [MaxLength(255, ErrorMessage = "Name cannot exceed 255 characters")]
        public string Name { get; set; }

        [Required(ErrorMessage = "Please enter a Task Description")]
        [MaxLength(2000, ErrorMessage = "Description cannot exceed 2000 characters")]
        public string Description { get; set; }

        [Required(ErrorMessage = "Please choose a Task Category")]
        public int? CategoryID { get; set; }

        [Required(ErrorMessage = "Please enter your name or requester's name")]
        public string Requester { get; set; }

        [Required(ErrorMessage = "Please enter your email address or requester's email address")]
        public string RequesterEmail { get; set; }

        public DateTime? RequestDate { get; set; }

        public DateTime? DueDate { get; set; }

        public DateTime? CompletedDate { get; set; }

        public int? RequestedPriorityLevel { get; set; }

        public int? AssignedPriorityLevel { get; set; }

        public TaskModel()
        {
        }

        public TaskModel(Guid id, string name, string description, int categoryID, string requester, string requesterEmail
                         , DateTime requestDate, DateTime dueDate, int requestedPriorityLevel)
        {
            this.Id = id;
            this.Name = name;
            this.Description = description;
            this.CategoryID = categoryID;
            this.Requester = requester;
            this.RequesterEmail = requesterEmail;
            this.RequestDate = RequestDate;
            this.DueDate = dueDate;
            this.RequestedPriorityLevel = requestedPriorityLevel;
        }


    }

    public class CategoriesModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public class TaskListViewModel
    {
        public Guid? Id { get; set; }

        [Required(ErrorMessage = "Please enter a Task Name")]
        [MaxLength(255, ErrorMessage = "Name cannot exceed 255 characters")]
        public string Name { get; set; }

        [Required(ErrorMessage = "Please enter a Task Description")]
        [MaxLength(2000, ErrorMessage = "Description cannot exceed 2000 characters")]
        public string Description { get; set; }

        [Required(ErrorMessage = "Please choose a Task Category")]
        public int? CategoryID { get; set; }

        [Required(ErrorMessage = "Please enter your name or requester's name")]
        public string Requester { get; set; }

        [Required(ErrorMessage = "Please enter your email address or requester's email address")]
        public string RequesterEmail { get; set; }
        [DataType(DataType.Date)]
        public DateTime? DueDate { get; set; }

        public int? RequestedPriorityLevel { get; set; }

        public List<TaskModel> Tasks { get; set; }
        public List<CategoriesModel> Categories { get; set; }

        public TaskListViewModel()
        {
            this.Tasks = new List<TaskModel>();
        }

        public void SaveTask(TaskModel task)
        {
            if (this.Tasks.Exists(n => n.Id == task.Id))
            {
                var temp = this.Tasks.First(n => n.Id == task.Id);
                temp = task;
            }
            else
            {
                this.Tasks.Add(task);
            }
        }

        public void DeleteTask(Guid id)
        {
            this.Tasks.Remove(this.Tasks.First(n => n.Id == id));
        }

    }
}